//
//  Device_y.swift
//  Library_y
//
//  Created by JC on 2023/6/6.
//

import Foundation
import UIKit
import DeviceKit

// 当前环境配置
#if DEBUG
     // 测试
     public let debugMode: Bool = true
#else
     // HOC，appstore
     public let debugMode: Bool = false
#endif

/// 常用常量
public struct Device_y {
     
    /// 屏幕大小
    static public let screenSize = UIScreen.main.bounds.size
    
    /// 屏幕宽度
    static public let screenWidth = UIScreen.main.bounds.width
    
    /// 屏幕高度
    static public let screenHeight = UIScreen.main.bounds.height
    
    /// 状态栏的高度
    static public let statusBarHeight = UIApplication.shared.statusBarFrame.height
    
    /// 导航栏的高度
    static public let navHeight : CGFloat = 44.0 + statusBarHeight
    
    /// 底部有空白
    static public let hasBottomSpace = !(iPhone_4_4s || iPhone_5_5s_5c_SE  || iPhone_6_6s_7_8 || iPhone_6p_6sp_7p_8p)
    
    /// 底部空白区域高度
    static public let bottomWhiteHeight : CGFloat = hasBottomSpace ? 34 : 0
    
    /// 分栏的高度
    static public let tabBarHeight : CGFloat = 49 + bottomWhiteHeight
    
    /// 内容高度
    static public let contentHeight: CGFloat = screenHeight - navHeight - tabBarHeight

}

extension Device_y {
    
    /// iPhone 4/4s（3.5寸）宽高比 0.6666
    static public var iPhone_4_4s: Bool {
        return UIScreen.main.bounds.size == CGSize(width: 320, height: 480)
    }
    
    /// iPhone 5/5s/5c/SE（4.0寸）宽高比 0.5633
    static public var iPhone_5_5s_5c_SE: Bool {
        return UIScreen.main.bounds.size == CGSize(width: 320, height: 568)
    }
    
    /// iPhone 6/6s/7/8（4.7寸）宽高比 0.5622
    static public var iPhone_6_6s_7_8: Bool {
        return UIScreen.main.bounds.size == CGSize(width: 375, height: 667)
    }
    
    /// iPhone 6P/6sP/7P/8P（5.5寸）宽高比 0.5625
    static public var iPhone_6p_6sp_7p_8p: Bool {
        return UIScreen.main.bounds.size == CGSize(width: 414, height: 736)
    }

    /// iPhone X/Xs/11 Pro（5.8寸）宽高比 0.4618
    static public var iPhone_11pro: Bool {
        return UIScreen.main.bounds.size == CGSize(width: 375, height: 812)
    }
    
    /// iPhone Xs Max/11 Pro Max（6.5寸）宽高比 0.4620
    static public var iPhone_11_11proMax: Bool {
        return UIScreen.main.bounds.size == CGSize(width: 414, height: 896)
    }
    
    /// iPhone 12mini（5.4寸）宽高比 0.4615
    static public var iPhone_12mini: Bool {
        return UIScreen.main.bounds.size == CGSize(width: 375, height: 812)
    }
    
    /// iPhone 12/12pro（6.1寸）宽高比 0.4621
    static public var iPhone_12pro: Bool {
        return UIScreen.main.bounds.size == CGSize(width: 390, height: 844)
    }
    
    /// iPhone 12pro max（6.7寸）宽高比 0.4622
    static public var iPhone_12proMax: Bool {
        return UIScreen.main.bounds.size == CGSize(width: 428, height: 926)
    }
    
}

extension Double {
    
    // 手机屏幕宽度相对于iphone6比例
    public var autoW: Double {
        return (self.toCGFloat * Device_y.screenWidth / 375.0).toDouble
     }
    
    // 手机屏幕高度相对于iphone6比例
    public var autoH: Double {
        return (self.toCGFloat * Device_y.screenWidth / 667.0).toDouble
    }
}

extension Int {

    
    // 手机屏幕宽度相对于iphone6比例
    public var autoW: Int {
        return (self.toCGFloat * Device_y.screenWidth / 375.0).toInt
    }
    
    // 手机屏幕高度相对于iphone6比例
    public var autoH: Int {
        return (self.toCGFloat * Device_y.screenWidth / 667.0).toInt
    }
}

extension NSLayoutConstraint {
    
    /// 屏幕适配
    public func adpW(_ w: Int) {
        self.constant = w.autoW.toCGFloat
    }
    
    /// 屏幕适配
    public func adpH(_ h: Int) {
        self.constant = h.autoH.toCGFloat
    }
}

extension Device_y {
    
    // 获取设备类型 iphone12 proMax
    static public func deviceType() -> String {
        return Device.current.description
    }
    
    // 获取设备名称 例如：梓辰的手机
    static public func deviceName() -> String {
        return UIDevice.current.name
    }
    
    // 获取系统名称 例如：iPhone OS
    static public func systemName() -> String {
        return UIDevice.current.systemName
    }
    
    // 获取系统版本 例如：9.2
    static public func sysVersion() -> String {
        return UIDevice.current.systemVersion
    }
    
    // 获取设备唯一标识符
    static public func deviceUUID() -> String {
        return UIDevice.current.identifierForVendor?.uuidString ?? ""
    }
    
    // 获取设备的型号 例如：iPhone
    static public func deviceModel() -> String {
        return UIDevice.current.model
    }
}
